package com.miracle.main.module.mvp.model;

import com.miracle.basemvp.base.BaseModel;
import com.miracle.basemvp.lifecycle.rx.RxSchedulersHelper;
import com.miracle.basemvp.network.IRetrofitManager;
import com.miracle.basemvp.network.download.RetrofitClient;
import com.miracle.common.mvp.entity.request.CheckVersionRequest;
import com.miracle.main.module.api.MainApi;
import com.miracle.main.module.mvp.contract.SettingContract;
import com.miracle.common.mvp.entity.response.DandelionResponse;
import com.miracle.common.mvp.entity.response.VersionInfo;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.MultipartBody;
import okhttp3.ResponseBody;

/**
 * com.miracle.main.module.mvp.model
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/7 13:25
 * @see com.miracle.main.module.mvp.model
 */
public class SettingModel extends BaseModel implements SettingContract.Model {

    @Inject
    public SettingModel(IRetrofitManager retrofitManager) {
        super(retrofitManager);
    }

    @Override
    public Observable<DandelionResponse<VersionInfo>> checkVersion(CheckVersionRequest request) {
        return mRetrofitManager
                .obtainRetrofitService(MainApi.class)
                .checkVersion(request.get_api_key(),request.getAppKey())
                .compose(RxSchedulersHelper.<DandelionResponse<VersionInfo>>io_main());
    }

    @Override
    public Observable<ResponseBody> downloadApk() {
        return null;
    }

    @Override
    public Observable<ResponseBody> uploadFiles(String url, MultipartBody body, String session) {
        return mRetrofitManager
                .obtainRetrofitService(MainApi.class)
                .uploadTx(url, body)
                .compose(RxSchedulersHelper.<ResponseBody>io_main());
    }
}
